<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		#box{width: 100px;height: 100px;background-color: red;position: absolute; }
	</style>
</head>
<body>
	<div id="box"></div>
</body>
<script type="text/javascript">
var box = document.getElementById("box");
	box.style.top = 0;
	box.style.left = 0;
	var s=false,x=false,z=false,y=false;
document.onkeydown = function(ev){
	if (ev.keyCode == 38) {
		s=true;
		box.style.top = parseInt(box.style.top) - 50 +"px";
	}
	if (ev.keyCode == 40) {
		x=true;
		box.style.top = parseInt(box.style.top) + 50 +"px";
	}
	if (ev.keyCode == 37) {
		z=true;
		box.style.left = parseInt(box.style.left) - 50 +"px";
	}
	if (ev.keyCode == 39) {
		y=true;
		box.style.left = parseInt(box.style.left) + 50 +"px";
	}
	if (s && z) {
		box.style.top = parseInt(box.style.top) - 50 +"px";
		box.style.left = parseInt(box.style.left) - 50 +"px";
	}
	if (s && y) {
		box.style.top = parseInt(box.style.top) - 50 +"px";
		box.style.left = parseInt(box.style.left) + 50 +"px";
	}
	if (x && z) {
		box.style.top = parseInt(box.style.top) + 50 +"px";
		box.style.left = parseInt(box.style.left) - 50 +"px";
	}
	if (x && y) {
		box.style.top = parseInt(box.style.top) + 50 +"px";
		box.style.left = parseInt(box.style.left) + 50 +"px";
	}
	box.style.transition = "0.5s";
}
document.onkeyup = function(ev){
	if (ev.keyCode == 38) {
		s = false;
	}
	if (ev.keyCode == 40) {
		x = false
	}
	if (ev.keyCode == 37) {
		z = false;
	}
	if (ev.keyCode == 39) {
		y = false;
	}
}
</script>
</html>